package com.yunzheng.studyLeaveSystem.modules.user.user_info.servlet; /**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/01/31/16:45
 * @Description:
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import com.yunzheng.studyLeaveSystem.modules.user.user_info.service.User_infoService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
/*
 *修改密码
 */
@WebServlet(name = "UpdatePasswordServlet", value = "/UpdatePasswordServlet")
public class UpdatePasswordServlet extends HttpServlet {
    private User_infoService user_infoService = new User_infoService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.setAttribute("id",7);
        int id = (int) session.getAttribute("id");
        //获取请求体数据
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        //将JSON字符转化为JAVA对象
        JSONObject jsonObject = JSON.parseObject(readLine);
        String password1 = jsonObject.getString("password1");
        String password2 = jsonObject.getString("password2");
        String password3 = jsonObject.getString("password3");
        ResponseWrapper responseWrapper = null;
        try {
            responseWrapper = user_infoService.updatePassword(password1, password2, password3, id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        String s = JSON.toJSONString(responseWrapper);
        response.getWriter().write(s);
        System.out.println(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
